# -*- coding: utf-8 -*-


"""
    作业二：
    请设计一个装饰器，它可以作用于任何函数上，打印函数执行时间：
    import time
    def metric(fn):
    start_time = time.time()
    end_time = time.time()

    print('耗时：{:.4f}s'.format(end_time - start_time))
    return fn
"""
import time


def metric(fn):

    def showtime(*args, **kw):
        start_time = time.time()
        res = fn(*args, **kw)
        end_time = time.time()
        print(
            '开始时间: {0}, 结束时间: {1}, 运行耗时: {2} 秒'
            .format(
                start_time, end_time, end_time-start_time
            )
        )
        return res
    return showtime


@metric
def HelloWorld():
    print("Hello World is Run!")
    time.sleep(2)


@metric
def HelloPython():
    print("Hello Python is Run!")
    time.sleep(2)


HelloWorld()
HelloPython()
